<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">          
<title>Validator</title>
</head>
<body>

	${corpo}

<script type="text/javascript" src="${pageContext.request.contextPath}/resources/componentes/importacoes/plugin-validator/dist/jquery.validate.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/componentes/importacoes/plugin-validator/dist/additional-methods.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/componentes/validator/js/Validator.js"></script>
<script type="text/javascript">

	var jsonOptions = "";
	<c:if test="${not empty debug}"> 
		var debug = ${debug};
		jsonOptions = $.extend(jsonOptions,{"debug":debug});
	
	</c:if>

	<c:if test="${not empty submitHandler}">
		var submitHandler = ${submitHandler};
		jsonOptions = $.extend(jsonOptions,{"submitHandler":submitHandler});
		
	</c:if>

	<c:if test="${not empty ignore}">
		var ignore = "${ignore}";
		jsonOptions = $.extend(jsonOptions,{"ignore":$(ignore)});
	</c:if>

	<c:if test="${not empty invalidHandler}"> 
		var invalidHandler = ${invalidHandler};
		jsonOptions = $.extend(jsonOptions,{"invalidHandler":invalidHandler});
	</c:if>

	<c:if test="${not empty groups}"> 
		var invalidHandler = ${groups};
		jsonOptions = $.extend(jsonOptions,{"groups":groups});
	</c:if>	

	<c:if test="${not empty onsubmitValidator}"> 
		var onsubmitValidator = ${onsubmitValidator};
		jsonOptions = $.extend(jsonOptions,{"onsubmit":onsubmitValidator});
	</c:if>	

	<c:if test="${not empty onfocusout}"> 
		var onfocusout = ${onfocusout};
		jsonOptions = $.extend(jsonOptions,{"onfocusout":onfocusout});
	</c:if>

	<c:if test="${not empty onkeyupValidator}"> 
		var onkeyupValidator = ${onkeyupValidator};
		jsonOptions = $.extend(jsonOptions,{"onkeyup":onkeyupValidator});
	</c:if>

	<c:if test="${not empty onclickValidator}">
		var onclickValidator = ${onclickValidator};
		<c:if test ="${onclickValidator eq 'false'}">
			jsonOptions = $.extend(jsonOptions,{"onclick":onclickValidator});	
		</c:if>
		<c:if test ="${onclickValidator ne 'false'}">
			jsonOptions = $.extend(jsonOptions,{"onclick":onclickValidator});	
		</c:if>	
	</c:if>

	<c:if test="${not empty focusCleanup}"> 
		var focusCleanup = ${focusCleanup};
		jsonOptions = $.extend(jsonOptions,{"focusCleanup":focusCleanup});
	</c:if>

	<c:if test="${not empty errorPlacement}"> 
		var errorPlacement = ${errorPlacement};
		jsonOptions = $.extend(jsonOptions,{"errorPlacement":errorPlacement});
	</c:if>

	<c:if test="${not empty highlight}"> 
		var highlight = ${highlight};
		<c:if test="${highlight eq 'true'}">
			jsonOptions = $.extend(jsonOptions,{
	
				highlight(element, error){
	
					$(element).fadeOut(function(){
						
							$(element).fadeIn();
								           
			    	});
	
				}
			});
				  
		</c:if>
	</c:if>

	<c:if test="${not empty unhighlight}"> 
		var unhighlight = ${unhighlight};
		<c:if test="${unhighlight eq 'true'}">
		jsonOptions = $.extend(jsonOptions,{

			unhighlight(element, error){

				$(element).fadeOut(function() {
					
						$(element).fadeIn().addClass('valid');	
							           
		    	});

			}
		});
		</c:if>
	</c:if>


	<c:if test="${not empty ignoreTitle}"> 
		var ignoreTitle = ${ignoreTitle};
		jsonOptions = $.extend(jsonOptions,{"ignoreTitle":ignoreTitle});
	</c:if>
	

	<c:if test="${not empty customFunctionValidation}">

		var customFunctionValidation = ${customFunctionValidation};
		jsonOptions = $.extend(jsonOptions,{"customFunctionValidation":customFunctionValidation}); 	
	
	</c:if>

	var stringDivErro = "";

	var seletorErro = $("#msgErro");
	
	<c:if test="${seletorErro.length ne 0}">

		stringDivErro = '<div id="msgErro"></div>';
		$("#" + "${form}").prepend(stringDivErro);
		$("#msgErro").hide();
		
	</c:if>

	var flagJsp = true;

	console.log(jsonOptions);
	
	validator.construirValidador("#" + "${form}", jsonOptions, flagJsp);
	
	<c:set var="debug" value=""></c:set>
	<c:set var="submitHandler" value=""></c:set>
	<c:set var="ignore" value=""></c:set>
	<c:set var="invalidHandler" value=""></c:set>
	<c:set var="onsubmitValidator" value=""></c:set>
	<c:set var="onfocusout" value=""></c:set>
	<c:set var="onkeyupValidator" value=""></c:set>
	<c:set var="onclickValidator" value=""></c:set>
	<c:set var="focusCleanup" value=""></c:set>
	<c:set var="errorPlacement" value=""></c:set>
	<c:set var="highlight" value=""></c:set>
	<c:set var="unhighlight" value=""></c:set>
	<c:set var="ignoreTitle" value=""></c:set>
	<c:set var="customFunctionValidation" value=""></c:set>
	
	
</script>

</body>
</html>